﻿using AutoMapper;
using J.Model;
using J.ProductSet.Application.Command.AggregateCommodityCommand;
using MediatR;
using SqlSugar;

namespace J.ProductSet.Application.CommandHandler.AggregateCommodityCommandHandler
{
    public class AggregateUpdateCommandHandler : IRequestHandler<AggregateUpdateCommand, int>
    {
        private readonly ISqlSugarClient _sqlSugarClient;
        public IMapper _mapper;
        public AggregateUpdateCommandHandler(ISqlSugarClient sqlSugarClient, IMapper mapper)
        {
            _sqlSugarClient = sqlSugarClient;
            _mapper = mapper;
        }
        public async Task<int> Handle(AggregateUpdateCommand request, CancellationToken cancellationToken)
        {
            AggregateCommodity Aggregate = _mapper.Map<AggregateCommodity>(request);
            return await _sqlSugarClient.Updateable(Aggregate).ExecuteCommandAsync();
        }
    }
}
